package com.skzh.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.skzh.common.core.domain.model.LoginUser;
import com.skzh.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.skzh.common.annotation.Log;
import io.swagger.annotations.ApiOperation;
import com.skzh.common.core.controller.BaseController;
import com.skzh.common.core.domain.AjaxResult;
import com.skzh.common.enums.BusinessType;
import com.skzh.equipment.domain.HailerModelInfo;
import com.skzh.equipment.service.IHailerModelInfoService;
import com.skzh.common.utils.poi.ExcelUtil;
import com.skzh.common.core.page.TableDataInfo;

/**
 * 喊话器型号信息Controller
 *
 * @author skzh
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/equipment/model")
public class HailerModelInfoController extends BaseController {
    @Autowired
    private IHailerModelInfoService hailerModelInfoService;

    /**
     * 查询喊话器型号信息列表
     */
    @ApiOperation(value = "查询喊话器型号信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:model:list')")
    @GetMapping("/list" )
    public TableDataInfo list(HailerModelInfo hailerModelInfo) {
        startPage();
        List<HailerModelInfo> list = hailerModelInfoService.selectHailerModelInfoList(hailerModelInfo);
        return getDataTable(list);
    }

    /**
     * 导出喊话器型号信息列表
     */
    @ApiOperation(value = "导出喊话器型号信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:model:export')" )
    @Log(title = "喊话器型号信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, HailerModelInfo hailerModelInfo) {
        List<HailerModelInfo> list = hailerModelInfoService.selectHailerModelInfoList(hailerModelInfo);
        ExcelUtil<HailerModelInfo> util = new ExcelUtil<HailerModelInfo>(HailerModelInfo. class);
        util.exportExcel(response, list, "喊话器型号信息数据" );
    }

    /**
     * 获取喊话器型号信息详细信息
     */
    @ApiOperation(value = "获取喊话器型号信息详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:model:query')" )
    @GetMapping(value = "/{modelId}" )
    public AjaxResult getInfo(@PathVariable("modelId" ) Long modelId) {
        return success(hailerModelInfoService.selectHailerModelInfoByModelId(modelId));
    }

    /**
     * 新增喊话器型号信息
     */
    @ApiOperation(value = "新增喊话器型号信息")
    @PreAuthorize("@ss.hasPermi('equipment:model:add')" )
    @Log(title = "喊话器型号信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HailerModelInfo hailerModelInfo) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        hailerModelInfo.setCreateBy(loginUser.getUsername());
        return toAjax(hailerModelInfoService.insertHailerModelInfo(hailerModelInfo));
    }

    /**
     * 修改喊话器型号信息
     */
    @ApiOperation(value = "修改喊话器型号信息")
    @PreAuthorize("@ss.hasPermi('equipment:model:edit')" )
    @Log(title = "喊话器型号信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HailerModelInfo hailerModelInfo) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        hailerModelInfo.setUpdateBy(loginUser.getUsername());
        return toAjax(hailerModelInfoService.updateHailerModelInfo(hailerModelInfo));
    }

    /**
     * 删除喊话器型号信息
     */
    @ApiOperation(value = "删除喊话器型号信息")
    @PreAuthorize("@ss.hasPermi('equipment:model:remove')" )
    @Log(title = "喊话器型号信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{modelIds}" )
    public AjaxResult remove(@PathVariable Long[] modelIds) {
        return toAjax(hailerModelInfoService.deleteHailerModelInfoByModelIds(modelIds));
    }
}
